Town X Dashboard (The Recent Month)

Column

Chart- Population Pyramid

Column

Chart-Known Sickness

Chart- Current Sickness (symptoms)

Row

Chart - Sought Health Facility

Chart - Main Percieved community health problem (Main_PCHP)

Town X Dashboard (Trend)

Column

Summary Table

Trend of community health and health related problems by month,Town X, Country x: January - June, 2025
January
(N=105)
February
(N=105)
March
(N=105)
April
(N=105)
May
(N=105)
June
(N=105)

Assess-Month= The Month of data collection and reporting; Known_Sick= Known Sickness; Current_Sick= Current Sickness(symptom); sough_hf=Sought health facility; Main_PCHP= Main perceived communinuty health problem (Data Source: Author, 2025. A Hypothetical Community Health Data for Exercise (Hypottowndata20.csv))

Known_Sick
Heart problem 4 (16.7%) 4 (16.0%) 5 (19.2%) 5 (19.2%) 8 (21.1%) 8 (21.1%)
Hypertension 5 (20.8%) 5 (20.0%) 5 (19.2%) 5 (19.2%) 10 (26.3%) 10 (26.3%)
Diabetes Mellitus 5 (20.8%) 6 (24.0%) 6 (23.1%) 6 (23.1%) 6 (15.8%) 6 (15.8%)
Cancer 2 (8.3%) 2 (8.0%) 2 (7.7%) 2 (7.7%) 2 (5.3%) 2 (5.3%)
Asthma (CORP) 6 (25.0%) 6 (24.0%) 6 (23.1%) 6 (23.1%) 8 (21.1%) 8 (21.1%)
Other 2 (8.3%) 2 (8.0%) 2 (7.7%) 2 (7.7%) 4 (10.5%) 4 (10.5%)
current_sick
Only Fever 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%)
Only Cough 5 (83.3%) 5 (83.3%) 5 (71.4%) 5 (71.4%) 7 (41.2%) 7 (41.2%)
Fever and Cough 0 (0%) 0 (0%) 0 (0%) 0 (0%) 5 (29.4%) 5 (29.4%)
Fever and Rash 0 (0%) 0 (0%) 0 (0%) 0 (0%) 1 (5.9%) 1 (5.9%)
Other 1 (16.7%) 1 (16.7%) 2 (28.6%) 2 (28.6%) 4 (23.5%) 4 (23.5%)
sought_hf
Yes 6 (60.0%) 6 (60.0%) 10 (71.4%) 10 (71.4%) 21 (70.0%) 22 (71.0%)
No 4 (40.0%) 4 (40.0%) 4 (28.6%) 4 (28.6%) 9 (30.0%) 9 (29.0%)
Main_PCHP
Drinking water problem 6 (16.7%) 6 (16.7%) 6 (16.7%) 6 (16.7%) 6 (16.7%) 6 (16.7%)
Sanitation problem 2 (5.6%) 2 (5.6%) 2 (5.6%) 2 (5.6%) 2 (5.6%) 2 (5.6%)
Food insecurity 5 (13.9%) 5 (13.9%) 6 (16.7%) 6 (16.7%) 7 (19.4%) 7 (19.4%)
Air pollution 8 (22.2%) 8 (22.2%) 8 (22.2%) 8 (22.2%) 8 (22.2%) 8 (22.2%)
Respiratory problem 4 (11.1%) 4 (11.1%) 4 (11.1%) 4 (11.1%) 4 (11.1%) 4 (11.1%)
Sound pollution in the residential area 2 (5.6%) 2 (5.6%) 2 (5.6%) 2 (5.6%) 2 (5.6%) 2 (5.6%)
Theft of resources impacting health 3 (8.3%) 3 (8.3%) 4 (11.1%) 4 (11.1%) 5 (13.9%) 5 (13.9%)
Other 6 (16.7%) 6 (16.7%) 4 (11.1%) 4 (11.1%) 2 (5.6%) 2 (5.6%)

Column

Line Graph - Known Sickness

Line Graph- Current Sickness (symptoms)

Row

Line Graph - Sought Health Facility

Line Graph - Main Percieved community health problem (Main_PCHP)

District 1 Dashboard (The Recent Month)

Column

Chart -1.1 Sex

Column

Chart-1.2 Known Sickness

Chart-1.3 Current Sickness (symptoms)

Row

Chart -1.4 Sought Health Facility

Chart - 1.5 Main Percieved community health problem (Main_PCHP)

District 1 Dashboard (Trend)

Column

Summary Table-1.1

Trend of community health and health related problems by month,District 1 Town X, Country x: January - June, 2025
January
(N=31)
February
(N=31)
March
(N=31)
April
(N=31)
May
(N=31)
June
(N=31)

Assess-Month= The Month of data collection and reporting; Known_Sick= Known Sickness; Current_Sick= Current Sickness(symptom); sough_hf=Sought health facility; Main_PCHP= Main perceived communinuty health problem (Data Source: Author, 2025. A Hypothetical Community Health Data for Exercise (Hypottowndata20.csv))

Known_Sick
Heart problem 0 (0%) 0 (0%) 1 (10.0%) 1 (10.0%) 2 (16.7%) 2 (16.7%)
Hypertension 2 (25.0%) 2 (25.0%) 3 (30.0%) 3 (30.0%) 4 (33.3%) 4 (33.3%)
Diabetes Mellitus 2 (25.0%) 2 (25.0%) 2 (20.0%) 2 (20.0%) 2 (16.7%) 2 (16.7%)
Cancer 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%)
Asthma (CORP) 3 (37.5%) 3 (37.5%) 3 (30.0%) 3 (30.0%) 3 (25.0%) 3 (25.0%)
Other 1 (12.5%) 1 (12.5%) 1 (10.0%) 1 (10.0%) 1 (8.3%) 1 (8.3%)
current_sick
Only Fever 1 (25.0%) 1 (25.0%) 1 (25.0%) 1 (25.0%) 2 (28.6%) 2 (28.6%)
Only Cough 2 (50.0%) 2 (50.0%) 2 (50.0%) 2 (50.0%) 3 (42.9%) 3 (42.9%)
Fever and Cough 0 (0%) 0 (0%) 0 (0%) 0 (0%) 1 (14.3%) 1 (14.3%)
Fever and Rash 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%)
Other 1 (25.0%) 1 (25.0%) 1 (25.0%) 1 (25.0%) 1 (14.3%) 1 (14.3%)
sought_hf
Yes 3 (75.0%) 3 (75.0%) 3 (60.0%) 3 (60.0%) 7 (77.8%) 7 (77.8%)
No 1 (25.0%) 1 (25.0%) 2 (40.0%) 2 (40.0%) 2 (22.2%) 2 (22.2%)
Main_PCHP
Drinking water problem 1 (10.0%) 1 (10.0%) 1 (10.0%) 1 (10.0%) 1 (10.0%) 1 (10.0%)
Sanitation problem 2 (20.0%) 2 (20.0%) 2 (20.0%) 2 (20.0%) 2 (20.0%) 2 (20.0%)
Food insecurity 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%)
Air pollution 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%)
Respiratory problem 2 (20.0%) 2 (20.0%) 2 (20.0%) 2 (20.0%) 2 (20.0%) 2 (20.0%)
Sound pollution in the residential area 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%) 0 (0%)
Theft of resources impacting health 3 (30.0%) 3 (30.0%) 4 (40.0%) 4 (40.0%) 5 (50.0%) 5 (50.0%)
Other 2 (20.0%) 2 (20.0%) 1 (10.0%) 1 (10.0%) 0 (0%) 0 (0%)

Column

Line Graph-1.1 Known Sickness

Line Graph-1.2 Current Sickness (symptoms)

Row

Line Graph-1.3 Sought Health Facility

Line Graph- 1.4 Main Percieved community health problem (Main_PCHP)

Pivot Table

Pivot Table of the recent month (dateRDLM) community health data of the household members in town X, country X

Data Table

Data Table of longitudinal (long form) Community Health Data of Town-X with its three Districts (named as 1, 2 and 3), Country x, dateRP

References

Column

References

1- The Graph Course. EPIREP_EN_parameterizing_reports.Rmd, Accessed on April 30, 2025: (https://thegraphcourses.org/courses/epirep/topics/parametrizing-reports)

2- Batra N., Spina A., Blomquiist P., et al. The Epidemiologist R Handbook, Sep 18, 2024. https://www.epirhandbook.com/en/new_pages/flexdashboard.html

3- https://www.youtube.com/watch?v=_a4S4tq62OE

4- https://www.youtube.com/watch?v=ef8qvUeopN4

5- Rich, Benjamin.Using the table 1 Package to create HTML tables of DESCRIPTIVE STATISTICS, Accessed on 21/07/2025: https://cran.r-project.org/web/packages/table1/vignettes/table1-examples.html#example-1

6- Stack Over Flow. How to order a ggplot x-axis by a variable containing a date range, Accessed on 18/07/2025: https://stackoverflow.com/questions/69247869/how-to-order-a-ggplot-x-axis-by-a-variable-containing-a-date-range

7- Rich, Benjamin. Package ‘table1’: Tables of Descriptive Statistics in HTML, 2023-01-05. https://github.com/benjaminrich/table1

Contact Me

Column

Contact Me

---
title: "Simple Community Health Dashboard (SCH_Dashboard)"
author: "Chernet Hailu Mengesha"
date: "`r Sys.Date()`"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
    theme: yeti
dateRDLM: "June 30, 2025"
dateRP: "January - June, 2025"
---

```{r setup, include=FALSE}
library(flexdashboard)

pacman::p_load(knitr, here, rmarkdown, tidyverse,
               DT, scales, plotly, patchwork,  readr, stringr,
               forcats, memisc, pyramid, janitor, paletteer,
               ggsci, pwalk, rpivotTable, highcharter, htmltools,
               viridis, outbreaks, ggrepel, ggthemes, zoo, options(scipen=999),table1)
# Load the dataset
#longitudinal data - monthly assessment for the same households (hypothetical data)
Hypottowndata20 <- read_csv("../DataLense/Hypottowndata20.csv")

#data prep1
Hypottowndata21 <- Hypottowndata20 %>% mutate(Agegr = cut(Ageyrc, breaks = c(0, 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54,59, 64, Inf),
                                                          labels = c('0-4', '5-9', '10-14', '15-19', '20-24', '25-29', '30-34', '35-39', '40-44', '45-49','50-54', '55-59', '60-64', '>64')))

Hypottowndata21T<-Hypottowndata21 %>% subset(Assess_month == "June") #The recent month data of town-x

#Defined-specific version of date()
date1<- format(Sys.time(), "%b %d,%Y")
dateRDLM <- paste("June 30,2025")
dateRP <- paste("January - June, 2025")

# Defined district names
District<-c("1", "2", "3")
```

Sidebar {.sidebar}
==============================

### An Example of Simple Community Health (SCH) Dashboard for a Town & a District (For Exercise)

The SCH_Dashboard is a households based community health data dashboard of the recent month and trend data.

Please try to review this dashboard and let's work as a team for its improvement. You can get my address by clicking on the "Contact Me" menu.

   *The best comes as a result of collaborative endeavor!*
   
# Town X Dashboard (The Recent Month)

## Column {.tableset data-width=500}

### Chart- Population Pyramid

```{r}
pyramidT<-function(Hypottowndata21T){
  # Create new subset
  pyramid_data <- 
    Hypottowndata21T %>% 
    
    # Count total cases by age group and gender
    count(Agegr, Sex, name = "total") %>%  
    
    # Create new columns for x-axis values on the plot
    mutate(
      # New column with axis values - convert male counts to negative
      axis_counts = ifelse(Sex == "Male", -total, total),
      # New column for percentage axis values
      axis_percent = round(100 * (axis_counts / nrow(Hypottowndata21T)), 
                           digits = 1))
  Hypottown_pyramid <- 
    ggplot() +
    
    geom_col(data = pyramid_data, #specify data to graph
             aes(
               x = Agegr,    # indicate x variable
               y = axis_counts,  # indicate NEGATED y variable
               fill = Sex))  +   # fill by sex
    theme_light() +
    coord_flip()
  
  max_count <- max(pyramid_data$total)
  
  custom_axes <- 
    
    # Use previous graph
    Hypottown_pyramid +
    
    # Adjust y-axis (total count)  
    scale_y_continuous(
      
      # Specify limit of y-axis using max value and making positive and negative
      limits = c(-max_count, max_count),
      
      # Specify the spacing between axis labels
      breaks = scales::breaks_width(4),
      
      # Make axis labels absolute so male labels appear positive
      labels = abs)
  
  custom_labels <- 
    
    # Start with previous demographic pyramid
    custom_axes +
    
    # Adjust the labels
    labs(
      title = paste("Town X households by Age and Sex", dateRDLM),
      subtitle = "Analysis of a Hypothetical Community Health Data",
      x = "Age Group",
      y = "Count", 
      fill = "Sex",
      caption = stringr::str_glue("Data are from a Hypothetical data for Exercise \nn = {nrow(Hypottowndata21T)}"))
  
  custom_color_theme <- 
    
    # Use previous graph
    custom_labels +
    
    # Designate colors and legend labels manually
    scale_fill_manual(
      
      # Select color of sex fill
      values = c("Female" = "lightblue",
                 "Male" = "darkblue"))+
    
    # Adjust theme settings
    theme(
      axis.line = element_line(colour = "black"), # make axis line black
      plot.title = element_text(hjust = 0.5),     # center title
      plot.subtitle = element_text(hjust = 0.5),  # center subtitle
      plot.caption = element_text(hjust = 0,      # format caption text
                                  size = 11, 
                                  face = "italic")) 
  print(custom_color_theme)
}
pyramidT(Hypottowndata21T)

```

## Column {data-width=500}

### Chart-Known Sickness {.no-padding}

```{r}
chartknsT<-function(Hypottowndata21T){
  Sumbydistkndxd <- Hypottowndata21T %>% group_by(District, Known_Sick) %>% summarise(n = n())
  
  Percbydistkndxd  <- Sumbydistkndxd %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  #Group Bar Chart
  Known_Sickness_Chart<- ggplot(Percbydistkndxd, aes(x = District, y = percentage, fill = Known_Sick)) +
    geom_col(position = "dodge") +
    labs(title = paste("Town X Household Members' with Known Sickness by district, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(Hypottowndata21T)} (Hypottowndata20.csv)"),
         x= "District",
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90))
  
  Known_Sickness_Chart
}
chartknsT(Hypottowndata21T)
```

### Chart- Current Sickness (symptoms){.no-padding}

```{r}
chartcurskT<-function(Hypottowndata21T){
  
  Sumbydistcurskd <- Hypottowndata21T %>% group_by(District, current_sick) %>% summarise(n = n())
  
  Percbydistcurskd  <- Sumbydistcurskd %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  #Group Bar Chart
  Current_Sickness_Chart<- ggplot(Percbydistcurskd, aes(x = District, y = percentage, fill = current_sick)) +
    geom_col(position = "dodge") +
    labs(title = paste("Town-X Household Members' with Current Sickness(Symtom) by district, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(Hypottowndata21T)} (Hypottowndata20.csv)"),
         x= "District",
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90))
  
  Current_Sickness_Chart
}
chartcurskT(Hypottowndata21T)
```

## Row
### Chart - Sought Health Facility

```{r}
chartsouhfT<-function(Hypottowndata21T){
  
  distsouhfild <-Hypottowndata21T %>% filter(current_sick != "No")
  
  Sumbydistsouhfd <-distsouhfild %>% group_by(District, sought_hf) %>% summarise(n=n())
  
  Percbydistsouhfd  <- Sumbydistsouhfd %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  #Group Bar Chart
  Sought_hf_Chart<- ggplot(Percbydistsouhfd, aes(x = District, y = percentage, fill = sought_hf)) +
    geom_col(position = "dodge") +
    labs(title = paste("Town X Household Members Sought Health Facility for the Current Sickness by district, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(distsouhfild)} (Hypottowndata20.csv)"),
         x= "District",
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90)) +
    coord_flip()
  Sought_hf_Chart
}
chartsouhfT(Hypottowndata21T)
```

### Chart - Main Percieved community health problem (Main_PCHP)

```{r}
chartchpT<-function(Hypottowndata21T){
  Sumbydistchpfild <-Hypottowndata21T %>% filter(Relation_to_hhh == "Household Head")
  
  Sumbydistchpd <-Sumbydistchpfild %>% group_by(District, Main_PCHP) %>% summarise(n=n())
  
  Percbydistchpd  <- Sumbydistchpd %>%
    mutate(percentage = round((n / sum(n))*100, 1)) %>%
    arrange(by=District, desc(percentage))
  
  #Group Bar Chart
  Main_PCHP_Chart <-
    ggplot(Percbydistchpd, aes(x = District, y = percentage,
                               fill = Main_PCHP)) +
    geom_col(position = "dodge") +
    labs(title = paste("Town X, District Household Members'Main Perceived Community Health Problem, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(Sumbydistchpfild)} (Hypottowndata20.csv)"),
         x= "District",
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90)) +
    coord_flip()
  Main_PCHP_Chart
}
chartchpT(Hypottowndata21T)
```

# Town X Dashboard (Trend)

## Column {.tableset data-width=650}

### Summary Table

```{r}
#Summary table of Town X community health and health related problems by month, Country x
stabT<- function(Hypottowndata21){
  dfstabT<- Hypottowndata21 %>% 
    mutate(Known_Sick= factor(Known_Sick, levels= c("Heart problem", "Hypertension", "Diabetes Mellitus", "Cancer", "Asthma (CORP)", "Other")),
           current_sick= factor(current_sick, levels = c("Only Fever ", "Only Cough", "Fever and Cough", "Fever and Rash", "Other")),
           sought_hf= factor(sought_hf, levels = c("Yes", "No")),
           Main_PCHP= factor(Main_PCHP, levels = c("Drinking water problem", "Sanitation problem", "Food insecurity", "Air pollution","Respiratory problem", "Sound pollution in the residential area", "Theft of resources impacting health", "Other")),
           Assess_month= factor(Assess_month, levels = c("January", "February", "March", "April", "May", "June")))
  
  caption<-paste("Trend of community health and health related problems by month,Town X, Country x:", dateRP)
  footnote<- "Assess-Month= The Month of data collection and reporting; Known_Sick= Known Sickness; Current_Sick= Current Sickness(symptom); sough_hf=Sought health facility; Main_PCHP= Main perceived communinuty health problem
  (Data Source: Author, 2025. A Hypothetical Community Health Data for Exercise (Hypottowndata20.csv))"
  
  stabT<-table1(~ Known_Sick + current_sick + sought_hf + Main_PCHP | Assess_month,
                data=dfstabT, na.is.category = F, render.missing=NULL, topclass="Rtable1-zebra", overall=F, caption=caption, footnote=footnote)
stabT
}
stabT(Hypottowndata21)
```

## Column {data-width=350}

### Line Graph - Known Sickness {.no-padding}

```{r}
# Display plot of trend of Known Sickness in a town by the assessment months 
#on the same respondent households of the community

lplotknsT<-function(Hypottowndata21){
  Sumbydistkndxd <- Hypottowndata21 %>% group_by(Assess_month, Known_Sick) %>%
    summarise(n = n())
  
  Percbydistkndxd  <- Sumbydistkndxd %>%
    mutate(percentage = round((n / sum(n))*100, 1)) 
  
  Percbydistkndxd2<- Percbydistkndxd %>% mutate(Assess_month = factor(Assess_month,
                                                                      levels = c("January", "February",
                                                                                 "March", "April", "May", "June")))
  #line plot
  Known_Sickness_plot<- ggplot(Percbydistkndxd2, aes(x = Assess_month,
                                                     y = percentage, color = Known_Sick, group = Known_Sick)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of known Sickness repoted by respondent houshold members of town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  Known_Sickness_plot
}
lplotknsT(Hypottowndata21)
```

### Line Graph- Current Sickness (symptoms){.no-padding}

```{r}
# Trend of current Sicknesss (symptoms) of the hh members of the town

lplotcurskT<-function(Hypottowndata21){
  
  Sumbydistcurskd <- Hypottowndata21 %>% group_by(Assess_month, current_sick) %>% summarise(n = n())
  
  Percbydistcurskd  <- Sumbydistcurskd %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  Percbydistcurskd2<- Percbydistcurskd %>% mutate(Assess_month = factor(Assess_month,
                                                                        levels = c("January", "February",
                                                                                   "March", "April", "May", "June")))
  #line plot
  current_Sickness_plot<- ggplot(Percbydistcurskd2, aes(x = Assess_month,
                                                        y = percentage, color = current_sick, group = current_sick)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of current sickness repoted by respondent houshold members of town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  current_Sickness_plot
}
lplotcurskT(Hypottowndata21)
```

## Row
### Line Graph - Sought Health Facility

```{r}
# Trend of the hh members of the town Sought Health Facility 

lplotsouhfT<-function(Hypottowndata21){
  
  distsouhfild <-Hypottowndata21 %>% filter(current_sick != "No")
  
  Sumbydistsouhfd <-distsouhfild %>% group_by(Assess_month, sought_hf) %>% summarise(n=n())
  
  Percbydistsouhfd  <- Sumbydistsouhfd %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  Percbydistsouhfd2<- Percbydistsouhfd %>% mutate(Assess_month = factor(Assess_month,
                                                                        levels = c("January", "February",
                                                                                   "March", "April", "May", "June")))
  #line plot
  Sought_hf_plot<- ggplot(Percbydistsouhfd2, aes(x = Assess_month,
                                                 y = percentage, color = sought_hf, group = sought_hf)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of respondent houshold members sought health facility, town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  Sought_hf_plot
}
lplotsouhfT(Hypottowndata21)
```

### Line Graph - Main Percieved community health problem (Main_PCHP)

```{r}
### Trend of Main Perceived community health problem (Main_PCHP) of the hh members of the town

lplotpchpT<-function(Hypottowndata21){
  Sumbydistchpfild <-Hypottowndata21 %>% filter(Relation_to_hhh == "Household Head")
  
  Sumbydistchpd <-Sumbydistchpfild %>% group_by(Assess_month, Main_PCHP) %>% summarise(n=n())
  
  Percbydistchpd  <- Sumbydistchpd %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  Percbydistchpd2<- Percbydistchpd %>% mutate(Assess_month = factor(Assess_month,
                                                                    levels = c("January", "February",
                                                                               "March", "April", "May", "June")))
  #line plot
  Main_PCHP_plot<- ggplot(Percbydistchpd2, aes(x = Assess_month,
                                               y = percentage, color = Main_PCHP, group = Main_PCHP)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of perceived main community health problem of respondent houshold members, town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  Main_PCHP_plot
}
lplotpchpT(Hypottowndata21)
```

# District 1 Dashboard (The Recent Month)

## Column {.tableset data-width=500}

### Chart -1.1 Sex

```{r}
crsexpie <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21T, District == district_name)
  
  Sumbysexdata0 <- subtowndata0 %>% group_by(Sex) %>% summarise(n = n())
  
  Percentage_data0 <- Sumbysexdata0 %>% 
    mutate(percentage = round((n / sum(n))*100, 1))
  
  percentage_pie0 <-
    ggplot(Percentage_data0, aes(x = " ", y=percentage,fill=Sex)) +
    geom_col() +
    coord_polar(theta = "y")+
    geom_text(aes(label = paste(percentage, "\ %")),
              position = position_stack(vjust = 0.5), # Center the label
              color = "white",
              fontface = "bold") +
    labs(title = paste("Sex of persons in the households of district", district_name, "town X, country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of data \nn = {nrow(subtowndata0)} from a hypothetical data (hypottowndata20)")) +
    theme_void()+
    scale_fill_viridis_d()
}

#create pie of sex distribution for district 1
piesexd1<-function(Hypottowndata21T){
  plots<- lapply(District[[1]], crsexpie)
  #Print the plot
  for(i in seq_along(plots)){print(plots[[1]])}
}
piesexd1(Hypottowndata21T)
```

## Column {data-width=500}

### Chart-1.2 Known Sickness {.no-padding}

```{r}
crKnSbarch <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21T, District == district_name)
  
  
  Sumbydistkndxd0 <- subtowndata0 %>% group_by(Known_Sick) %>% summarise(n = n())
  
  Percbydistkndxd0  <- Sumbydistkndxd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  #Group Bar Chart
  Known_Sickness_Chart<- ggplot(Percbydistkndxd0, aes(x = " " , y = percentage, fill = Known_Sick)) +
    geom_col(position = "dodge") +
    labs(title = paste("District", district_name, "Household Members' with Known Sickness, Town X, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(subtowndata0)} (Hypottowndata20.csv)"),
         x= "Known_Sickness",
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90)) 
}

#create bchart of known sickness distribution for district 1
barchKnSd1<-function(Hypottowndata21T){
  bcharts<- lapply(District[[1]], crKnSbarch)
  #Print the bchart
  for(i in seq_along(bcharts)){print(bcharts[[1]])}
}
barchKnSd1(Hypottowndata21T)
```

### Chart-1.3 Current Sickness (symptoms){.no-padding}

```{r}
curSbarch <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21T, District == district_name)
  
  
  Sumbydistcurskd0 <- subtowndata0 %>% group_by(current_sick) %>% summarise(n = n())
  
  Percbydistcurskd0  <- Sumbydistcurskd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  #Group Bar Chart
  Current_Sickness_Chart<- ggplot(Percbydistcurskd0, aes(x = " ", y = percentage, fill = current_sick)) +
    geom_col(position = "dodge") +
    labs(title = paste("District", district_name, "Household Members' with Current Sickness, Town X, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(subtowndata0)} (Hypottowndata20.csv)"),
         x= paste("District", district_name),
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90)) +
    coord_flip()
}

#create bchart of current sickness (symptoms) distribution for district 1
barcurSd1<-function(Hypottowndata21T){
  curSbarchs<- lapply(District[[1]], curSbarch)
  #Print the bchart
  for(i in seq_along(curSbarchs)){print(curSbarchs[[1]])}
}
barcurSd1(Hypottowndata21T)
```

## Row

### Chart -1.4 Sought Health Facility

```{r}
souhfbarch <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21T, District == district_name)
  
  distsouhfild0 <-subset(subtowndata0, current_sick != "No")
  
  Sumbydistsouhfd0 <-distsouhfild0 %>% group_by(sought_hf) %>% summarise(n=n())
  
  Percbydistsouhfd0  <- Sumbydistsouhfd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  #Group Bar Chart
  Sought_hf_Chart<- ggplot(Percbydistsouhfd0, aes(x = " ", y = percentage, fill = sought_hf)) +
    geom_col(position = "dodge") +
    labs(title = paste("District", district_name, "Household Members' Sought Health Facility for the Current Sickness, Town X, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(distsouhfild0)} (Hypottowndata20.csv)"),
         x= paste("District", district_name),
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90))
}

#create bchart of sought health facility distribution for district 1
barsouhfd1<-function(Hypottowndata21T){
  souhfbarchs<- lapply(District[[1]], souhfbarch)
  #Print the bchart
  for(i in seq_along(souhfbarchs)){print(souhfbarchs[[1]])}
}
barsouhfd1(Hypottowndata21T)
```

### Chart - 1.5 Main Percieved community health problem (Main_PCHP)

```{r}
MPCHPbarch <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21T, District == district_name)
  
  Sumbydistchpfild0 <-subtowndata0  %>% filter(Relation_to_hhh == "Household Head")
  
  Sumbydistchpd0 <-Sumbydistchpfild0 %>% group_by(Main_PCHP) %>% summarise(n=n())
  
  Percbydistchpd0  <- Sumbydistchpd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1)) %>%
    arrange(by=Main_PCHP, desc(percentage))
  
  # Group Bar Chart
  Main_PCHP_Chart <-
    ggplot(Percbydistchpd0, aes(x = " ", y = percentage,
                                fill = Main_PCHP)) +
    geom_col(position = "dodge") +
    labs(title = paste("District", district_name, "Household Members' Main Perceived Community Health Problem,Town X, Country X", dateRDLM),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise \nn = {nrow(Sumbydistchpfild0)} (Hypottowndata20.csv)"),
         x= paste("District", district_name),
         y= "Household Members, %") +
    theme(axis.text.x = element_text(angle = 90)) +
    coord_flip()
}

#create bchart of MPCHP distribution for district 1
barMPCHPd1<-function(Hypottowndata21T){
  MPCHPbarchs<- lapply(District[[1]], MPCHPbarch)
  #Print the bchart
  for(i in seq_along(MPCHPbarchs)){print(MPCHPbarchs[[1]])}
}
barMPCHPd1(Hypottowndata21T)
```

# District 1 Dashboard (Trend)

## Column {.tableset data-width=650}

### Summary Table-1.1

```{r}
#Summary table of each District community health and health related problems by month, Town X, Country x
stabD<- function(district_name){
  dfstabD<- subset(Hypottowndata21, District == district_name) %>% 
    mutate(Known_Sick= factor(Known_Sick, levels= c("Heart problem", "Hypertension", "Diabetes Mellitus", "Cancer", "Asthma (CORP)", "Other")),
           current_sick= factor(current_sick, levels = c("Only Fever", "Only Cough", "Fever and Cough", "Fever and Rash", "Other")),
           sought_hf= factor(sought_hf, levels = c("Yes", "No")),
           Main_PCHP= factor(Main_PCHP, levels = c("Drinking water problem", "Sanitation problem", "Food insecurity", "Air pollution","Respiratory problem", "Sound pollution in the residential area", "Theft of resources impacting health", "Other")),
           Assess_month= factor(Assess_month, levels = c("January", "February", "March", "April", "May", "June")))
  caption<-paste("Trend of community health and health related problems by month,District", district_name,"Town X, Country x:", dateRP)
  footnote<- "Assess-Month= The Month of data collection and reporting; Known_Sick= Known Sickness; Current_Sick= Current Sickness(symptom); sough_hf=Sought health facility; Main_PCHP= Main perceived communinuty health problem
  (Data Source: Author, 2025. A Hypothetical Community Health Data for Exercise (Hypottowndata20.csv))"
  
  stabDtab<-table1(~ Known_Sick + current_sick + sought_hf + Main_PCHP | Assess_month,
                   data=dfstabD, na.is.category = F, render.missing=NULL,  topclass="Rtable1-zebra", overall=F, caption=caption, footnote=footnote)
  stabDtab
}

stabD(District[[1]]) 
```

## Column {data-width=350}

### Line Graph-1.1 Known Sickness {.no-padding}

```{r}
lplotKnSD <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21, District == district_name)
  
  
  Sumbydistkndxd0 <- subtowndata0 %>% group_by(Assess_month, Known_Sick) %>% summarise(n = n())
  
  Percbydistkndxd0  <- Sumbydistkndxd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  Percbydistkndxd2<- Percbydistkndxd0 %>% mutate(Assess_month = factor(Assess_month,
                                                                       levels = c("January", "February",
                                                                                  "March", "April", "May", "June")))
  #line plot
  Known_Sickness_plot<- ggplot(Percbydistkndxd2, aes(x = Assess_month,
                                                     y = percentage, color = Known_Sick, group = Known_Sick)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of known Sickness repoted by respondent houshold members of District", district_name, "Town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  Known_Sickness_plot
}

#Trend of known sickness of district 1
lplotKnSD1<-function(Hypottowndata21){
  lplots<- lapply(District[[1]], lplotKnSD)
  #Print the line plot
  print(lplots[[1]])
}
lplotKnSD1(Hypottowndata21)
```

### Line Graph-1.2 Current Sickness (symptoms){.no-padding}

```{r}
lplotcurSD <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21, District == district_name)
  
  
  Sumbydistcurskd0 <- subtowndata0 %>% group_by(Assess_month, current_sick) %>% summarise(n = n())
  
  Percbydistcurskd0  <- Sumbydistcurskd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  Percbydistcurskd2<- Percbydistcurskd0 %>% mutate(Assess_month = factor(Assess_month,
                                                                         levels = c("January", "February",
                                                                                    "March", "April", "May", "June")))
  #line plot
  current_sickness_plot<- ggplot(Percbydistcurskd2, aes(x = Assess_month,
                                                        y = percentage, color = current_sick, group = current_sick)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of current sickness repoted by respondent houshold members of District", district_name, "Town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  current_sickness_plot
}

#Trend of current sickness of district 1
lplotcurSD1<-function(Hypottowndata21){
  lplots<- lapply(District[[1]], lplotcurSD)
  #Print the line plot
  print(lplots[[1]])
}
lplotcurSD1(Hypottowndata21)
```

## Row

### Line Graph-1.3 Sought Health Facility

```{r}
lplotsouhfD <- function(district_name) {
  
  subtowndata0 <- subset(Hypottowndata21, District == district_name)
  
  distsouhfild0 <-subset(subtowndata0, current_sick != "No")
  
  Sumbydistsouhfd0 <-distsouhfild0 %>% group_by(Assess_month, sought_hf) %>% summarise(n=n())
  
  Percbydistsouhfd0  <- Sumbydistsouhfd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  
  Percbydistsouhfd2<- Percbydistsouhfd0 %>% mutate(Assess_month = factor(Assess_month,
                                                                         levels = c("January", "February",
                                                                                    "March", "April", "May", "June")))
  #line plot
  sought_hf_plot<- ggplot(Percbydistsouhfd2, aes(x = Assess_month,
                                                 y = percentage, color = sought_hf, group = sought_hf)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of respondent houshold members sought health facility, District", district_name, "Town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  sought_hf_plot
}

#Trend of sought health facility of district 1
lplotsouhfD1<-function(Hypottowndata21){
  lplots<- lapply(District[[1]], lplotsouhfD)
  #Print the line plot
  print(lplots[[1]])
}
lplotsouhfD1(Hypottowndata21)
```

### Line Graph- 1.4 Main Percieved community health problem (Main_PCHP)

```{r}
lplotMPCHPD <- function(district_name) {
  subtowndata0 <- subset(Hypottowndata21, District == district_name)
  Sumbydistchpfild0 <-subtowndata0  %>% filter(Relation_to_hhh == "Household Head")
  Sumbydistchpd0 <-Sumbydistchpfild0 %>% group_by(Assess_month, Main_PCHP) %>% summarise(n=n())
  Percbydistchpd0  <- Sumbydistchpd0 %>%
    mutate(percentage = round((n / sum(n))*100, 1))
  Percbydistchpd2<-  Percbydistchpd0 %>% mutate(Assess_month = factor(Assess_month,
                                                                      levels = c("January", "February",
                                                                                 "March", "April", "May", "June")))
  #line plot
  Main_PCHP_plot<- ggplot(Percbydistchpd2, aes(x = Assess_month,
                                               y = percentage, color = Main_PCHP, group = Main_PCHP)) +
    geom_line(linewidth = 1) + 
    geom_point() + 
    scale_color_discrete() +
    labs(title = paste("Trend of respondent houshold members perceived main community health problem, District", district_name, "Town X, Country X:", dateRP),
         subtitle = stringr::str_glue("Analysis of a Hypothetical Community Health Data for Exercise (Hypottowndata20.csv)"),
         x= "Month",
         y= "Household Members, %") +
    theme_classic()
  Main_PCHP_plot
}

#Trend of Main_PCHP of district 1
lplotMPCHPD1<-function(Hypottowndata21){
  lplots<- lapply(District[[1]], lplotMPCHPD)
  #Print the line plot
  print(lplots[[1]])
}
lplotMPCHPD1(Hypottowndata21)
```

# Pivot Table

### Pivot Table of the recent month (dateRDLM) community health data of the household members in town X, country X 

```{r}
pt1<-function(Hypottowndata21T){
  
  pt1<- (rpivotTable(Hypottowndata21T,
                     aggrigatorName = "Count",
                     cols= "Agegr",
                     rows= "Sex",
                     renderName= "Heatmap"))
  pt1
}
pt1(Hypottowndata21T)
```

# Data Table

### Data Table of longitudinal (long form) Community Health Data of Town-X with its three Districts (named as 1, 2 and 3), Country x, dateRP

```{r}
mydatatable<-function(Hypottowndata20){
  datatable<-datatable(Hypottowndata20,
                       caption = "My Hypothetical Community Health Data",
                       rownames = T,
                       filter = "top",
                       extensions = "Buttons", options = list(
                         dom ='Bfrtip',
                         buttons = c('copy', 'print', "csv")
                       ))
  datatable
}

mydatatable(Hypottowndata20)
```

# References {Data-orientation=columns}

## Column {Data-width=100}

### References

1- The Graph Course. EPIREP_EN_parameterizing_reports.Rmd, Accessed on April 30, 2025: (https://thegraphcourses.org/courses/epirep/topics/parametrizing-reports)

2- Batra N., Spina A., Blomquiist P., et al. The Epidemiologist R Handbook, Sep 18, 2024. https://www.epirhandbook.com/en/new_pages/flexdashboard.html

3- https://www.youtube.com/watch?v=_a4S4tq62OE

4- https://www.youtube.com/watch?v=ef8qvUeopN4

5-  Rich, Benjamin.Using the table 1 Package to create HTML tables of DESCRIPTIVE STATISTICS, Accessed on 21/07/2025: https://cran.r-project.org/web/packages/table1/vignettes/table1-examples.html#example-1

6- Stack Over Flow. How to order a ggplot x-axis by a variable containing a date range, Accessed on 18/07/2025: https://stackoverflow.com/questions/69247869/how-to-order-a-ggplot-x-axis-by-a-variable-containing-a-date-range

7- Rich, Benjamin. Package ‘table1’: Tables of Descriptive Statistics in HTML, 2023-01-05. https://github.com/benjaminrich/table1

# Contact Me {Data-orientation=columns}

## Column {Data-width=100}

### Contact Me

  - Chernet Hailu (MPH, Assist. Prof (On Retirement))
  - Email: chernet2013@gmail.com | chernet_mengesha@yahoo.com